package com.zhonghan.common.wechat.api;

import com.alibaba.fastjson.JSON;
import com.zhonghan.common.utils.HttpClientUtil;
import com.zhonghan.common.wechat.bean.result.BaseResult;
import com.zhonghan.common.wechat.bean.template.TemplateMsg;

/**
 * 模板消息API
 * @author zhangceven
 *
 */
public class TemplateMsgApi extends BaseResult{
	
	
	/**
	 * 发送模板消息
	 * @param access_token
	 * @param templateMsgJson 模板消息json数据
	 * @return
	 */
	public static BaseResult sendMessage(String access_token,String templateMsgJson){
		
		String url = "https://api.weixin.qq.com/cgi-bin/message/template/send"
				+ "?access_token=" + access_token;
		
		String result = HttpClientUtil.doPostJson(url , templateMsgJson);
		
		BaseResult baseResult = JSON.parseObject(result, BaseResult.class);
		
		return baseResult;
	}
	
	/**
	 * 发送模板消息
	 * @param access_token
	 * @param templateMsg 模板消息数据对象
	 * @return
	 */
	public static BaseResult sendMessage(String access_token,TemplateMsg templateMsg){
		
		String templateMsgJson = JSON.toJSONString(templateMsg);
		
		BaseResult baseResult = sendMessage(access_token, templateMsgJson);
		
		return baseResult;
		
	}
	
	

}
